package main

import (
	//"strings"
	"fmt"
	//"crypto/md5"
/*	"strconv"
	"time"
	"crypto/md5"
	"encoding/hex"
	"math/rand"*/
	reg "git.oschina.net/YPTArch/ypt_service_discovery"
	"time"
	"github.com/robfig/cron"
)

func main() {
	registerWatchTest()
	//discoveryWatchTest()
}


func registerWatchTest(){
	reg.NewRegisterClient([]string{"127.0.0.1:2379"},"/rpc/appname/servicename1/1.0",reg.RegisterInfo{
		Host : "127.0.0.2",
		Port : 3,
		Api : reg.ApiInfo{
			"GetName" : []string{"GET","1"},
			"GetDate" : []string{"GET","0"},
			"Submit" : []string{"POST","1"},
		},
	})
	//reg.NewRegWatchCli(r)//.WatchService("/rpc/appname/servicename1/1.0")
	select {

	}
}
func discoveryWatchTest(){
	d ,_ := reg.NewDiscoveryClient([]string{"127.0.0.1:2379"})
	key := "/rpc/appname/servicename1/1.0"
	c := cron.New()
	spec := "@every 2s"
	c.AddFunc(spec, func(){
		dd,err := d.RangeService(key)
		if err != nil{
			fmt.Println(err)
		}else{
			fmt.Println("data",dd)
		}


	})
	c.Start()
	select{

	}


}
func  check(){
	fmt.Println("check start")
	ticker := time.NewTicker(time.Millisecond * 1)
	done := make(chan bool)
	go func() {
		for t:= range ticker.C{
			fmt.Println("ticker",t)
		}

	}()
	<- done
	ticker.Stop()
	check()
}

//初始化注册服务
/*	var etcdEndPoints []string
	if os.Getenv("etcdhost") == ""{
		etcdEndPoints = []string{"127.0.0.1:2379"}
	}else{
		etcdEndPoints = strings.Split(os.Getenv("etcdhost"),";")
	}
	fmt.Println(len(etcdEndPoints),etcdEndPoints)*/
//	var appName,serviceName,version string
/*	if appName = os.Getenv("appname");appName == ""{
		appName = "appname"
	}

	if serviceName = os.Getenv("servicename");serviceName == ""{
		serviceName = "servicename"
	}
	if version = os.Getenv("version");version == ""{
		version = "1.0"
	}*/